package tp2;

import sort.impl.SelectionSorter;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Ejercicio3 {

    public static class NameComparator implements Comparator<NombreCompleto>{

        public int compare(NombreCompleto o1, NombreCompleto o2) {
            if((o1.getApellido()).compareToIgnoreCase(o2.getApellido())>0){
                return 1;
            } else if((o1.getApellido()).compareTo(o2.getApellido())==0){
                if((o1.getNombre()).compareToIgnoreCase(o2.getNombre())>0){
                    return 1;
                } else {
                    return -1;
                }
            } else {
                return -1;
            }
        }
    }

    public static void sort(List<NombreCompleto> list){
        SelectionSorter selectionSorter = new SelectionSorter();
        NameComparator nameComparator = new NameComparator();
        selectionSorter.sort(nameComparator,list);
        for (NombreCompleto aList : list) {
            System.out.println(aList.getApellido()+", "+aList.getNombre());
        }
    }
    
    public static void main(String[] args) {
        List<NombreCompleto> list= new ArrayList<NombreCompleto>();
        list.add(new NombreCompleto("Paula","Alonso"));
        list.add(new NombreCompleto("Diego","Diaz"));
        list.add(new NombreCompleto("Diego","Alonso"));
        sort(list);
    }
    
}
